<?php

namespace app\admin\model\inventory;

use think\Model;

class Lists extends Model
{
    // 表名
    protected $name = 'inventory_list';
    

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    protected $dateFormat = 'Y-m-d H:i:s';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    
    // 追加属性
    protected $append = [
        'instoragetime_text',
        'outstoragetime_text'
    ];
    

    
    public function getInstoragetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['instoragetime']) ? $data['instoragetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getOutstoragetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['outstoragetime']) ? $data['outstoragetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setInstoragetimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    protected function setOutstoragetimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
